package com.monkey_pig.memoryalbum.activity.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.monkey_pig.memoryalbum.R;
import com.monkey_pig.memoryalbum.activity.entity.ChildEntity;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Junerver on 2016/5/26.
 * gridview的适配器 用于加载图片
 */

public class GridImageAdapter extends BaseAdapter {
    private List<ChildEntity> list;
    private ChildEntity tempGridViewItem;
    private LayoutInflater layoutInflater;

    public GridImageAdapter(Context context, List<ChildEntity> list) {
        this.list = list;
        layoutInflater = LayoutInflater.from(context);

    }

    /**
     * 数据总数
     */
    @Override
    public int getCount() {

        return list.size();
    }

    /**
     * 获取当前数据
     */
    @Override
    public Object getItem(int position) {

        return list.get(position);
    }

    @Override
    public long getItemId(int position) {

        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder =null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.gridview_item, null);
            holder.imageView = (ImageView) convertView.findViewById(R.id.imageView1);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
            //获取自定义的类实例
            tempGridViewItem = list.get(position);
            holder.imageView.setImageBitmap(tempGridViewItem.bitmap);


        return convertView;
    }

    public static class ViewHolder {
        ImageView imageView;

    }
}